package com.example.vertification.controller;

import cn.hutool.extra.mail.Mail;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.example.vertification.Utils.MailUtil;
import com.example.vertification.entity.User;
import com.example.vertification.service.CartService;
import com.example.vertification.service.OrderService;
import com.example.vertification.service.UserAddressService;
import com.example.vertification.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Map;



@RestController
@Api(value = "意见反馈", tags = "意见反馈")
public class AdviceController {


    private final UserService userService;
    private  final MailUtil mu;
    public AdviceController(UserService userService,MailUtil mu) {
        this.userService = userService;
        this.mu = mu;
    }

    @PostMapping("/submit_advise")
    @ApiOperation(value = "传入用户的token、反馈的内容content")
    public ResponseEntity<?> submit_advise(@RequestBody String body) {
        JSONObject obj = (JSONObject) JSONUtil.parse(body);
        String token = obj.getStr("token");
        User u = userService.getUserByToken(token);
        if(u==null){
            return ResponseEntity.ok("请先登录");
        }
        String content = obj.getStr("content");
        String title = "秸秆云平台->有1枚用户提出了反馈,速来查看~";
        ArrayList<String> admin_list =new ArrayList<String>();
        admin_list.add("1341268754@qq.com");
        admin_list.add("1242839141@qq.com");
        admin_list.add("3027911710@qq.com");
        admin_list.add("2406034923@qq.com");
        ArrayList<String> user_data =new ArrayList<String>();
        user_data.add(String.valueOf(u.getUid()));
        user_data.add(u.getName());
        for(String email_acc:admin_list){
            mu.sendHtmlMail(email_acc,title,content,user_data);
        }
        return  new ResponseEntity<>("提交成功", HttpStatus.OK);
    }

}
